package moe.bogos.dourotest;

import moe.bogos.douro.api.common.Timer;
import net.minecraft.client.Minecraft;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.event.TickEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.common.Mod;

@Mod.EventBusSubscriber(modid = "dourotest")
public class EventSubscriber
{
    static int sum = 0;
    static int sum1 = 0;//有多少个runnable
    static int sum2 = 0;//成功执行了多少次
    static long sum3 = 0;//时间累加
    
    @SubscribeEvent
    public void onTick(TickEvent.ClientTickEvent event)
    {
        System.out.println("aaaa");
        if (event.phase == TickEvent.Phase.END)
        {
            sum++;
            if (sum > 1000)
            {
                if (sum > 1100)
                {
                    System.out.println("sum1=" + sum1);
                    System.out.println("sum2=" + sum2);
                    System.out.println("sum3=" + sum3);
                    System.out.println(((float) sum3) / sum2);
                    Minecraft.getInstance().close();
                }
                return;
            }
            for (int i = 0; i < 100; i++) Timer.schedule(2000, Dist.CLIENT, new C());
        }
    }
    
    private static class C implements Runnable
    {
        long time;
        
        C()
        {
            sum1++;
            time = System.currentTimeMillis();
        }
        
        public void run()
        {
            long t = System.currentTimeMillis();
            sum2++;
            sum3 += t - time;
        }
    }
}
